from django.contrib.auth.models import Permission,ContentType, Group
from rest_framework import serializers


class GroupPermSimpleSerializer(serializers.ModelSerializer):
    class Meta:
        model = Permission
        fields = [
            'id',
            'name'
        ]


class GroupModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = Group
        fields = [
            'id',
            'name',
            # 假设模型类序列化器可以完成该字段的校验和新建中间表数据；
            'permissions'
        ]

class PermContentTypeSerializer(serializers.ModelSerializer):
    class Meta:
        model = ContentType
        fields = [
            'id',
            'name'
        ]



class PermModelSerializer(serializers.ModelSerializer):

    class Meta:
        model = Permission
        fields = [
            'id',
            'name',
            'codename',
            'content_type'
        ]